﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace Web
{
    public partial class admin_ncadd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                BindNotice();
            }
        }

        private void BindNotice()
        {
            noticefail.Visible = false;
            noticesuccess.Visible = false;
        }
        protected void btnSubmit_OnClick(object sender, EventArgs e)
        {
            if(txbTitle.Text.Trim()==null){
                return;
            }
            NewsCategoryInfo newscategory = new NewsCategoryInfo();
            newscategory.CategoryName = txbTitle.Text.ToString().Replace("'","''");
            newscategory.HasNNews = 0;
            int isSuccess = NewsCategoryInfoLogic.AddNewsCategoryInfo(newscategory);
            if (isSuccess != 1)
            {
                ChangeStatus(false);
            }else{
                ChangeStatus(true);
            }
        }

        private void ChangeStatus(bool flag)
        {
            noticesuccess.Visible = flag?true:false;
            noticefail.Visible = flag?false:true;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "initclosenotice", "newsCategoryAdd('admin_newscategory.aspx',5000);", true);
        }
    }
}
